package com.winit.generator.task;

import com.winit.generator.framework.AbstractApplicationTask;
import com.winit.generator.framework.context.ApplicationContext;
import com.winit.generator.handler.BaseHandler;
import com.winit.generator.handler.impl.ServiceNewHandler;
import com.winit.generator.model.DaoInfo;

import java.util.List;

public class ServiceNewTask extends AbstractApplicationTask {

    private static String SERVICE_FTL = "template/ServiceNew.ftl";

    private List<DaoInfo> daoInfos;

    @SuppressWarnings("unchecked")
    @Override
    protected boolean doInternal(ApplicationContext context) {
        logger.info("开始生成Service");

        daoInfos = (List<DaoInfo>) context.getAttribute("daoList");

        BaseHandler<DaoInfo> handler = null;
        for (DaoInfo daoInfo : daoInfos) {
            handler = new ServiceNewHandler(SERVICE_FTL, daoInfo);
            handler.execute(context);
        }

        logger.info("生成Service完成");
        return false;
    }
}
